package com.dc.seckill.dao;

import com.dc.seckill.domain.MiaoshaGoods;
import com.dc.seckill.vo.GoodsVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @模块 商品模块
 * @作者 djs
 * @时间 2018/3/21 8:33
 * @版本 V1.0
 * @描述 对商品信息进行操作
 */
@Mapper
public interface GoodsDao {

    /**
     * 查询秒杀商品信息列表
     * @params []
     * @returns java.util.List<com.dc.seckill.vo.GoodsVo>
     */
    @Select("select g.*,m.stock_count, m.start_date, m.end_date,m.miaosha_price" +
            " from miaosha_goods m left join goods g on m.goods_id = g.id ")
    List<GoodsVo> listGoodsVo();

    /**
     * 查询秒杀商品信息
     * @params [goodsId]
     * @returns com.dc.seckill.vo.GoodsVo
     */
    @Select("select g.*,m.stock_count, m.start_date, m.end_date,m.miaosha_price" +
            " from miaosha_goods m left join goods g on m.goods_id = g.id " +
            " where m.goods_id = #{goodsId}")
    GoodsVo queryGoodsVoByGoodsID(@Param("goodsId") long goodsId);

    /**
     * 减秒杀库存
     * @params [g]
     * @returns int
     */
    @Update("update miaosha_goods set stock_count = stock_count - 1 where goods_id = #{goodsId}")
    public int reduceStock(MiaoshaGoods g);

}
